package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysUserWechat;
import com.ruoyi.system.service.ISysUserWechatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户微信绑定Controller
 * 
 * @author ruoyi
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/system/user_wechat")
public class SysUserWechatController extends BaseController
{
    @Autowired
    private ISysUserWechatService sysUserWechatService;

    /**
     * 查询用户微信绑定列表
     */
    @PreAuthorize("@ss.hasPermi('system:user_wechat:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserWechat sysUserWechat)
    {
        startPage();
        List<SysUserWechat> list = sysUserWechatService.selectSysUserWechatList(sysUserWechat);
        return getDataTable(list);
    }

    /**
     * 导出用户微信绑定列表
     */
    @PreAuthorize("@ss.hasPermi('system:user_wechat:export')")
    @Log(title = "用户微信绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserWechat sysUserWechat)
    {
        List<SysUserWechat> list = sysUserWechatService.selectSysUserWechatList(sysUserWechat);
        ExcelUtil<SysUserWechat> util = new ExcelUtil<SysUserWechat>(SysUserWechat.class);
        util.exportExcel(response, list, "用户微信绑定数据");
    }

    /**
     * 获取用户微信绑定详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:user_wechat:query')")
    @GetMapping(value = "/{wechatId}")
    public AjaxResult getInfo(@PathVariable("wechatId") Long wechatId)
    {
        return success(sysUserWechatService.selectSysUserWechatByWechatId(wechatId));
    }

    /**
     * 新增用户微信绑定
     */
    @PreAuthorize("@ss.hasPermi('system:user_wechat:add')")
    @Log(title = "用户微信绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserWechat sysUserWechat)
    {
        return toAjax(sysUserWechatService.insertSysUserWechat(sysUserWechat));
    }

    /**
     * 修改用户微信绑定
     */
    @PreAuthorize("@ss.hasPermi('system:user_wechat:edit')")
    @Log(title = "用户微信绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserWechat sysUserWechat)
    {
        return toAjax(sysUserWechatService.updateSysUserWechat(sysUserWechat));
    }

    /**
     * 删除用户微信绑定
     */
    @PreAuthorize("@ss.hasPermi('system:user_wechat:remove')")
    @Log(title = "用户微信绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wechatIds}")
    public AjaxResult remove(@PathVariable Long[] wechatIds)
    {
        return toAjax(sysUserWechatService.deleteSysUserWechatByWechatIds(wechatIds));
    }
}
